﻿using System.Windows;
using Framework.Abstractions.Wpf.Intefaces;

namespace CncConvProg.View.Dialog
{
    /// <summary>
    /// Interaction logic for LicenseWindow.xaml.
    /// 
    /// Se setto dialog result , la finestra si sente in diritto di chiudersi..
    /// </summary>
    public partial class LicenseWindow : Window, IModalWindow
    {
        public LicenseWindow()
        {
            InitializeComponent();
        }

        private void Button_Click_Exit(object sender, RoutedEventArgs e)
        {
            DialogResult = false;

            Close();
        }

        private static string RemoveSpaces(string p)
        {
            return p.Replace(" ", string.Empty);
        }
        ///// <summary>
        ///// Se chiave è valida , chiudo finestra
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
        }

        //    //   DialogResult = false;

        //    // var k = keyTb.Text; // mes. su riga vuota.

        //    if (!RptSen.ReportGenerator.PcId.CheckInternetConnection.IsConnectedToInternet())
        //    {
        //        MessageBox.Show("Connessione a internet necessaria", "Convalida Chiave Licenza", MessageBoxButton.OK,
        //                        MessageBoxImage.Warning, MessageBoxResult.None);
        //        return;
        //    }

        //    var ap = Application.Current as ILicensableApplication;

        //    var inputedKey = RemoveSpaces(keyTb.Text);

        //    if (ap != null)
        //    {
        //        // <returns>0 - Ok 1- Chiave Non Valida 2 - Scaduta 3 - errore generale
        //        var r = ap.UpdateLicense(inputedKey);
        //        switch (r)
        //        {
        //            case 0:
        //                {
        //                    MessageBox.Show("Chiave Valida ", "Convalida Chiave Licenza", MessageBoxButton.OK,
        //          MessageBoxImage.Information, MessageBoxResult.None);

        //                    DialogResult = true;
        //                    Close();
        //                } break;

        //            case 1:
        //                {
        //                    MessageBox.Show("Chiave Non Riconosciuta . \n", "Convalida Chiave Licenza", MessageBoxButton.OK,
        //        MessageBoxImage.Warning, MessageBoxResult.None);
        //                } break;

        //            case 2:
        //                {
        //                    MessageBox.Show("Chiave Scaduta . \n", "Convalida Chiave Licenza", MessageBoxButton.OK,
        //      MessageBoxImage.Warning, MessageBoxResult.None);
        //                } break;

        //            case 3:
        //                {
        //                    MessageBox.Show("Errore durante convalida. \n Controllare conessione internet .", "Convalida Chiave Licenza", MessageBoxButton.OK,
        //      MessageBoxImage.Warning, MessageBoxResult.None);
        //                } break;

        //        }
        //    }
        //}
    }
}
